package com.tool.tcpimg;
//飞行器
import com.tool.image.ImageMixDeal;
import com.tool.tcp.GetTcpPath;
import com.tool.tcp.NewPart;
import com.tool.tcp.Sprite;
import com.tool.tcp.SpriteFactory;
import come.tool.Fighting.sidian;
import org.come.bean.PathPoint;
import org.come.until.Util;

import java.awt.*;

public class Flyruntcp {

    private String skin;
    private int jg;
    private sidian sidians[];
    public NewPart newPart;
    public Flyruntcp(String skin) {
        this.skin = skin;
        sidians = new sidian[5];
        for (int i = 0; i < sidians.length; i++) {
            sidians[i] = new sidian(-1, 0, 0, 0);
        }

        jg = 30;
    }

    public Runnable draw(Graphics g, long time) {
        time = (long)((double)time /5);
        Sprite sprite = null;
        for (int i = 0; i < sidians.length; i++) {
            if (i == 0) {
            	sprite = SpriteFactory.Prepare(GetTcpPath.getflytcp(skin));//shadowMode  //GetTcpPath.getMouseTcp(skin)
            }
                
            if (sidians[i].getX() != -1) {
                sidians[i].setX((int)((long)sidians[i].getX() + time));//
                if (sprite != null) {
                	if (sidians[i].getX() <= sprite.getTime()) {
                		PathPoint pathPoint = Util.mapmodel.path(sidians[i].getZ(), sidians[i].getW());
                		if (pathPoint != null) {
                			sprite.updateToTime(sidians[i].getX(), sidians[i].getY());
                			sprite.drawfly(g, pathPoint.getX(), pathPoint.getY());
//                			sprite.drawflyShadow(g, ImageMixDeal.userimg.getRoleShow().getX(), ImageMixDeal.userimg.getRoleShow().getY());
                		}
                	} else {
                		sidians[i].setX(-1);
                	}
                }
            }
        }
        return null;
    }

    public void addfly(int x, int y, int dir) {
        if (Util.mapmodel.path(x, y) == null) {
        	return ;
        }
        for (int i = 0; i < sidians.length; i++) {
        	if (sidians[i].getX() == -1)  {
        		jg--;
        		if (jg < 0)
        		{
        			jg = 30;
        			sidians[i].setsidian(0, dir, x, y);
        		}
        		return ;
        	}
        }
    }

    public void setSkin(String skin) {
        this.skin = skin;
    }
}
